﻿using UnityEditor;
using UnityEngine;

namespace UnitAssetFramwork.UnitEditor
{

    public class ItemEditorPopup : EditorWindow
    {
        private SO_ItemData itemData; // 当前编辑的Item

        public static void ShowPopup(SO_ItemData item)
        {
            ItemEditorPopup window = GetWindow<ItemEditorPopup>("Edit Item");
            window.itemData = item;
            window.minSize = new Vector2(300, 250);
            window.Show();
        }

        private void OnGUI()
        {
            if (itemData == null)
            {
                GUILayout.Label("No item selected.", EditorStyles.boldLabel);
                return;
            }

            // 编辑Name
            itemData.Name = EditorGUILayout.TextField("Name", itemData.Name);

            // 编辑Description
            itemData.Description = EditorGUILayout.TextField("Description", itemData.Description);

            // 编辑Model
            itemData.GameObject = (GameObject)EditorGUILayout.ObjectField("Model", itemData.GameObject, typeof(GameObject), false);

            // 编辑Icon
            //itemData.Icon = (Sprite)EditorGUILayout.ObjectField("Icon", itemData.Icon, typeof(Texture2D), false);

            // 编辑AssetLink
            itemData.AssetLink = EditorGUILayout.TextField("Asset Link", itemData.AssetLink);

            // 保存按钮
            if (GUILayout.Button("Save"))
            {
                EditorUtility.SetDirty(itemData);
                AssetDatabase.SaveAssets();
                Close();
            }
        }
    }

}